program A_debug;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils,
  Math;

var
  f, g: TextFile;
  answer: Int64;
  T: Word;
  A: Integer;
  N: Word;
  B: array[1..100] of Integer;
  C: Array of Integer;

 procedure QuickSort(var A: array of Integer; iLo, iHi: Integer) ;
 var
   Lo, Hi, Pivot, T: Integer;
 begin
   Lo := iLo;
   Hi := iHi;
   Pivot := A[(Lo + Hi) div 2];
   repeat
     while A[Lo] < Pivot do Inc(Lo) ;
     while A[Hi] > Pivot do Dec(Hi) ;
     if Lo <= Hi then
     begin
       T := A[Lo];
       A[Lo] := A[Hi];
       A[Hi] := T;
       Inc(Lo) ;
       Dec(Hi) ;
     end;
   until Lo > Hi;
   if Hi > iLo then QuickSort(A, iLo, Hi) ;
   if Lo < iHi then QuickSort(A, Lo, iHi) ;
 end;

procedure ReadData;
var
  i: Word;
begin
  Readln(f, A, N);
  for i := 1 to N do
    Read(f, B[i]);
  Readln(f);
end;

function EstimateAnswerForHardCase(var CC: array of Integer; Start, HypotheticalAnswer, HypotheticalA: Integer): Integer;
var
  i: Word;
  ceiling, left, HypotheticalResult: Integer;
begin
  Result := HypotheticalAnswer;
  for i := Start to N do
    if HypotheticalA > CC[i - 1] then begin
      Inc(HypotheticalA, CC[i - 1]);
      Writeln('HypotheticalA is ', HypotheticalA, ' eaten ', CC[i - 1]);
    end
    else begin
      ceiling := Ceil(ln(CC[i - 1] / (HypotheticalA - 1)) / ln(2));
      left := N - i + 1;
      if (ceiling >= left) then begin
        Inc(Result, left);
        Writeln('Too much left, exiting, answer is ', Result, ' eaten ', CC[i - 1]);
        Exit;
      end else begin
        //HypotheticalA := ((HypotheticalA - 1) shl ceiling) + 1 + C[i - 1];
        HypotheticalA := ((HypotheticalA - 1) shl ceiling) + 1;
        if HypotheticalA > C[i - 1] then
          Inc(HypotheticalA, C[i - 1])
        else
          raise Exception.Create('Internal Error');

        HypotheticalResult := EstimateAnswerForHardCase(CC, i + 1, Result + ceiling, HypotheticalA);
        if (HypotheticalResult < Result + left) then
          Result := HypotheticalResult
        else
          Inc(Result, left);
        Exit;
      end;
    end;
end;

procedure ProcessData;
var
  i: Word;
  ceiling, left: Integer;
begin
  if (A = 1) then begin
    answer := N;
    Exit;
  end;

  SetLength(C, N);
  for i := 1 to N do
    C[i - 1] := B[i];
  QuickSort(C, 0, N - 1);
  answer := EstimateAnswerForHardCase(C, 1, 0, A);
{  for i := 1 to N do
    if A > C[i - 1] then begin
      Inc(A, C[i - 1]);
      Writeln('A is ', A, ' eaten ', C[i - 1]);
    end
    else begin
      ceiling := Ceil(ln(C[i - 1] / (A - 1)) / ln(2));
      left := N - i + 1;
      if (ceiling >= left) then begin
        Inc(answer, left);
        Writeln('Too much left, exiting, answer is ', answer, ' eaten ', C[i - 1]);
        Exit;
      end else begin
        //A := ((A - 1) shl ceiling) + 1 + C[i - 1];
        A := ((A - 1) shl ceiling) + 1;
        if A > C[i - 1] then
          Inc(A, C[i - 1])
        else
          raise Exception.Create('Internal Error');
        Inc(answer, ceiling);
      end;
    end;      }
end;


procedure OutputVerdict(casenum: Word);
begin
  writeln(g, 'Case #', casenum, ': ', answer);
end;

var
  i: Word;
  s: String;

begin
  try
    s := ParamStr(1);
    if (s = '') then
       s := 'input.txt';
    AssignFile(f, s);
    Reset(f);
    AssignFile(g, 'output.txt');
    Rewrite(g);
    try
      Readln(f, T);
      for i := 1 to T do begin
        ReadData;
        ProcessData;
        OutputVerdict(i);
      end;
    finally
      CloseFile(f);
      CloseFile(g);
    end;
    writeln('Reading finished');
  except
    on E: Exception do begin
      Writeln(E.ClassName, ': ', E.Message);
      readln;
    end;
  end;
end.
